              IOI.29 (Intersectii). Se dau la intrare numarul natural N si segmentele n plan
[a(i),b(i)], 1iN. Se cere sa se determine numarul maxim de segmente intersectate de o
aceeasi dreapta.
=============================================
Solutia 1 (Catalin Francu)
program Intersectii;
{$B-,I-,R-,S-}
const NMax=2500;
type PointType=record
                 X,Y:Real;
               end;
     PointVector=array[1..NMax] of PointType;
var A,B:PointVector;
    N,Best:Integer;

procedure ReadData;
var FileName:String;
    i:Integer;
begin
  Write('Numele fisierului de intrare (<Enter>=tastatura): ');
  ReadLn(FileName);
  Assign(Input,FileName);Reset(Input);
  Write('Numarul de puncte: ');ReadLn(N);
  WriteLn('Introduceti X1i Y1i X2i Y2i, cate un segment pe linie...');
  for i:=1 to N do ReadLn(A[i].X,A[i].Y,B[i].X,B[i].Y);
  Close(Input);
end;

function Equal(P,Q:PointType):Boolean;
begin
  Equal:=(P.X=Q.X) and (P.Y=Q.Y);
end;

function Count(P,Q:PointType):Integer;
var D,E,F:Real;
    i,Sum:Integer;
begin
  D:=Q.Y-P.Y;
  E:=P.X-Q.X;
  F:=-(P.X*D+P.Y*E);
  Sum:=0;
  for i:=1 to N do
    if (D*A[i].X+E*A[i].Y+F)*(D*B[i].X+E*B[i].Y+F)<=0
      then Inc(Sum);
  Count:=Sum;
end;

procedure FindBest;
var i,j,Cor:Integer;
begin
  Best:=0;
  for i:=1 to N-1 do
    for j:=i to N do
      begin
        if not Equal(A[i],A[j])
          then begin
                 Cor:=Count(A[i],A[j]);
                 if Cor>Best then Best:=Cor;
               end;
        if not Equal(A[i],B[j])
          then begin
                 Cor:=Count(A[i],B[j]);
                 if Cor>Best then Best:=Cor;
               end;
        if not Equal(B[i],A[j])
          then begin
                 Cor:=Count(B[i],A[j]);
                 if Cor>Best then Best:=Cor;
               end;
        if not Equal(B[i],B[j])
          then begin
                 Cor:=Count(B[i],B[j]);
                 if Cor>Best then Best:=Cor;
               end;
      end;
end;

begin
  ReadData;
  FindBest;
  WriteLn('Numarul maxim de segmente intersectate este ',Best);
end.
----------------------------------
